package io.github.codelifeleno.jdbrelease.model.finals;

import io.github.codelifeleno.jdbrelease.model.JDBReleaseRunModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;

public enum JDBReleaseRunStatus {

    READY("准备中") {
        public void changeStatus(JDBReleaseRunModel model) {
            log.debug("{}", model);
        }
    },
    RUNNING("运行中"){
        public void changeStatus(JDBReleaseRunModel model) {
            log.debug("{}", model);
            model.setRunStartTime(LocalDateTime.now());
            model.getRunInterval().start();
        }
    },
    END("结束"){
        public void changeStatus(JDBReleaseRunModel model) {
            log.debug("{}", model);
            model.setRunEndTime(LocalDateTime.now());
        }
    },
    ERROR("运行异常"){
        public void changeStatus(JDBReleaseRunModel model) {
            log.debug("{}", model);
            model.setRunEndTime(LocalDateTime.now());
        }
    }
    ;
    private static final Logger log = LoggerFactory.getLogger(JDBReleaseRunStatus.class);
    private final String name;
    JDBReleaseRunStatus(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }

    /**
     * 当属性状态变为该状态时运行
     * @param model 运行对象
     */
    public abstract void changeStatus(JDBReleaseRunModel model);
}
